<template>
    <div>
        <span style="width: 30px">姓名:</span>
        <span style="height: 50px">{{UserName}}</span>
        <el-transfer
                v-model="value2"
                :data="data2" @change="getUpdateRole" ></el-transfer>
        <br>
        <br>
        <template>
            <span>用户状态：</span>
            <el-radio v-model="radio" label="Y" @change="updatestatus" >有效</el-radio>
            <el-radio v-model="radio" label="N"  @change="updatestatus">无效</el-radio>
        </template>
        <br><br>

    </div>
</template>

<script>

    import SystemRoleService from '../../../model/mfy/system_user/SystemRoleService.js'
    const systemRoleService = SystemRoleService.getInstance()

    export default {
        props:['id'],
        data() {
            return {
                data2: [],
                value2: [],
                id2:this.id,
                UserName:'',
                radio: 'Y'
            };
        },
        created(){
            this.init()
        },
        watch:{
            id:function () {
                this.id2 = this.id
                this.init()
            }
        },
        methods:{

            init(){
                systemRoleService.init(this.id2).then(this.$axios.spread((response1,response2,response3)=> {
                    var datas =[]
                    response1.data.data.forEach( i =>{
                        datas.push({
                            key:i.id,
                            label:i.roleName,
                        })
                    })
                    this.data2=datas;

                    var a = []
                    response2.data.data.forEach( i=>{
                        a.push(i.id)
                    })
                    this.value2=a

                    this.UserName=response3.data.data.userRealname
                    this.radio=response3.data.data.userStatus
                }))
            },

            getUpdateRole(key,direction,key2){

                systemRoleService.getUserByUserId(this.id2).then((response)=>{
                    if(response.data.data.userStatus=='N'){
                        this.$message.error('该用户无效!!');
                        systemRoleService.getRoleByUserId(this.id2).then((response1)=>{
                            var a = []
                            response1.data.data.forEach( i=>{
                                a.push(i.id)
                            })
                            this.value2=a
                        })
                        return;
                    }else{
                        if(direction === 'right'){
                            systemRoleService.save(this.id,key2)
                        }else{
                            systemRoleService.remove(this.id,key2)

                        }

                    }
                })



            },
            updatestatus(){
                systemRoleService.updatestatus(this.id2,this.radio)
            }


        }
    };
</script>

<style scoped>

</style>
